//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __GHOSTCONDITION_H__
#define __GHOSTCONDITION_H__

#include <elasys_server.h>
#include <interlocked.h>
#include "ghost.h"

class CGhostCondition : public Ghost
{
public:
    UInt32 AddRef();
    UInt32 Release();

public:
    ECode Wait(
        /* [in] */ Millisecond32 msTimeOut,
        /* [out] */ WaitResult * pResult);

    ECode Pulse();
    ECode PulseAll();

public:
    CGhostCondition() : m_hCondition(NULL), m_hMutex(NULL) {}
    virtual ~CGhostCondition();
    ECode Initialize();

private:
    PVoid m_hCondition;
    PVoid m_hMutex;
private:
    Interlocked m_nRefs;
};

class CGhostConditionFactory : public GhostFactory
{
public:
    ECode CreateGhost(
        /* [out] */ Ghost ** ppGhost,
        /* [out] */ Boolean * pbExisted);

public:
    CGhostConditionFactory(WString name)
                  : GhostFactory(name, ObjectType_NamedCondition) {}
};

#endif //__GHOSTCONDITION_H__

